﻿camSchoolApp.service('dataLayerService', function ($http, $q) {
    this.userViewModel = null;
    this.treeViewModel = null;
    this.employeesViewModel = null;

    var baseUrl = "http://localhost:1984/CamSchoolWebService/rest/";

    this.loginAsynC = function () {
        var deferal = $q.defer();
        var loginUserUrl = "authentificationService/login/?username=" + $("#usernameInput").val() + "&password=" + $("#passwordInput").val();

        $http({ method: 'get', url: baseUrl + loginUserUrl }).success(function (data, status, headers, config) {
            deferal.resolve(data);
        }).error(function (data, status, headers, config) {
            deferal.reject(status);
        });
        return deferal.promise;
    }

    this.getClassRoomTypeAndChildrenAsynC = function () {
        var deferal = $q.defer();
        var classTreeUrl = "classRoomService/getClassRoomTypeAndChildren";

        $http({ method: 'get', url: baseUrl + classTreeUrl }).success(function (data, status, headers, config) {
            deferal.resolve(data);
        }).error(function (data, status, headers, config) {
            deferal.reject(status);
        });
        return deferal.promise;
    }

    this.getAllEmployeeAsynC = function () {
        var deferal = $q.defer();
        var employeeUrl = "employeeService/getAllEmployees";

        $http({ method: 'get', url: baseUrl + employeeUrl }).success(function (data, status, headers, config) {
            deferal.resolve(data);
        }).error(function (data, status, headers, config) {
            deferal.reject(status);
        });
        return deferal.promise;
    }
});
